<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>zookeeper系列一之入门 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="简介　　ZooKeeper是一个分布式的，开放源码的分布式应用程序协调服务，它包含一个简单的原语集，分布式应用程序可以基于它实现同步服务，配置维护和命名服务等。在分布式应用中，由于工程师不能很好地使用锁机制，以及基于消息的协调机制不适合在某些应用中使用，因此需要有一种可靠的、可扩展的、分布式的、可配置的协调机制来统一系统的状态。Zookeeper的目的就在于此。本文先介绍如何使用zookeeper">
<meta property="og:type" content="article">
<meta property="og:title" content="zookeeper系列一之入门">
<meta property="og:url" content="http://yoursite.com/2016/01/09/zookeeper/1.zookeeper系列之入门/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="简介　　ZooKeeper是一个分布式的，开放源码的分布式应用程序协调服务，它包含一个简单的原语集，分布式应用程序可以基于它实现同步服务，配置维护和命名服务等。在分布式应用中，由于工程师不能很好地使用锁机制，以及基于消息的协调机制不适合在某些应用中使用，因此需要有一种可靠的、可扩展的、分布式的、可配置的协调机制来统一系统的状态。Zookeeper的目的就在于此。本文先介绍如何使用zookeeper">
<meta property="og:updated_time" content="2016-01-29T17:47:36.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="zookeeper系列一之入门">
<meta name="twitter:description" content="简介　　ZooKeeper是一个分布式的，开放源码的分布式应用程序协调服务，它包含一个简单的原语集，分布式应用程序可以基于它实现同步服务，配置维护和命名服务等。在分布式应用中，由于工程师不能很好地使用锁机制，以及基于消息的协调机制不适合在某些应用中使用，因此需要有一种可靠的、可扩展的、分布式的、可配置的协调机制来统一系统的状态。Zookeeper的目的就在于此。本文先介绍如何使用zookeeper">
  
    <link rel="alternative" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="/css/style.css" type="text/css">
  

</head>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-zookeeper/1.zookeeper系列之入门" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2016/01/09/zookeeper/1.zookeeper系列之入门/" class="article-date">
  <time datetime="2016-01-08T17:00:00.000Z" itemprop="datePublished">2016-01-09</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/zookeeper/">zookeeper</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      zookeeper系列一之入门
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="u7B80_u4ECB"><a href="#u7B80_u4ECB" class="headerlink" title="简介"></a>简介</h2><p>　　ZooKeeper是一个分布式的，开放源码的分布式应用程序协调服务，它包含一个简单的原语集，分布式应用程序可以基于它实现同步服务，配置维护和命名服务等。在分布式应用中，由于工程师不能很好地使用锁机制，以及基于消息的协调机制不适合在某些应用中使用，因此需要有一种可靠的、可扩展的、分布式的、可配置的协调机制来统一系统的状态。Zookeeper的目的就在于此。本文先介绍如何使用zookeeper，后文再介绍其运行原理</p>
<h2 id="u5355_u8282_u70B9_u73AF_u5883_u642D_u5EFA"><a href="#u5355_u8282_u70B9_u73AF_u5883_u642D_u5EFA" class="headerlink" title="单节点环境搭建"></a>单节点环境搭建</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#zookeeper-3.4.5.tar.gz解压至/usr/local目录下</span></span><br><span class="line">tar -zxvf zookeeper-<span class="number">3.4</span>.<span class="number">5</span>.tar.gz</span><br><span class="line">mv zookeeper-<span class="number">3.4</span>.<span class="number">5</span> zookeeper</span><br><span class="line"></span><br><span class="line"><span class="comment">#新建zookeeper/conf/zoo.cfg文件：</span></span><br><span class="line">cp zoo_sample.cfg zoo.cfg</span><br><span class="line"><span class="comment">#并作如下修改，其他保持不变，并建立相应的文件夹</span></span><br><span class="line">dataDir=/usr/<span class="built_in">local</span>/zookeeper/data </span><br><span class="line">dataLogDir/usr/<span class="built_in">local</span>/zookeeper/<span class="built_in">log</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#配置环境变量：</span></span><br><span class="line"><span class="built_in">export</span> ZOOKEEPER_HOME=/usr/<span class="built_in">local</span>/zookeeper</span><br><span class="line"><span class="built_in">export</span> PATH=<span class="variable">$ZOOKEEPER_HOME</span>/bin:<span class="variable">$PATH</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#启动zookeeper服务</span></span><br><span class="line">bin/zkServer.sh start</span><br><span class="line"><span class="comment">#注意：在3.4.6版本的Windows环境下实测，启动命令为zkServer.cmd，没有参数start，</span></span><br><span class="line"><span class="comment">#否则会抛出异常java.lang.NumberFormatException: For input string: "D:\zookeeper-3.4.6\bin\..\co nf\zoo.cfg"</span></span><br></pre></td></tr></table></figure>
<h2 id="u591A_u673A_u96C6_u7FA4_u73AF_u5883_u642D_u5EFA"><a href="#u591A_u673A_u96C6_u7FA4_u73AF_u5883_u642D_u5EFA" class="headerlink" title="多机集群环境搭建"></a>多机集群环境搭建</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#修改conf/zoo.cfg配置文件如下</span></span><br><span class="line"><span class="comment"># The number of milliseconds of each tick</span></span><br><span class="line">tickTime=<span class="number">2000</span></span><br><span class="line"><span class="comment"># The number of ticks that the initial </span></span><br><span class="line"><span class="comment"># synchronization phase can take</span></span><br><span class="line">initLimit=<span class="number">10</span></span><br><span class="line"><span class="comment"># The number of ticks that can pass between </span></span><br><span class="line"><span class="comment"># sending a request and getting an acknowledgement</span></span><br><span class="line">syncLimit=<span class="number">5</span></span><br><span class="line"><span class="comment"># the directory where the snapshot is stored.</span></span><br><span class="line"><span class="comment"># do not use /tmp for storage, /tmp here is just </span></span><br><span class="line"><span class="comment"># example sakes.</span></span><br><span class="line">dataDir=/usr/<span class="built_in">local</span>/zookeeper-<span class="number">3.4</span>.<span class="number">6</span>/dataDir</span><br><span class="line">dataLogDir=/usr/<span class="built_in">local</span>/zookeeper-<span class="number">3.4</span>.<span class="number">6</span>/dataLogDir</span><br><span class="line"><span class="comment"># the port at which the clients will connect</span></span><br><span class="line">clientPort=<span class="number">2181</span></span><br><span class="line"><span class="comment"># the maximum number of client connections.</span></span><br><span class="line"><span class="comment"># increase this if you need to handle more clients</span></span><br><span class="line"><span class="comment">#maxClientCnxns=60</span></span><br><span class="line"><span class="comment"># The number of snapshots to retain in dataDir</span></span><br><span class="line"><span class="comment">#autopurge.snapRetainCount=3</span></span><br><span class="line"><span class="comment"># Purge task interval in hours</span></span><br><span class="line"><span class="comment"># Set to "0" to disable auto purge feature</span></span><br><span class="line"><span class="comment">#autopurge.purgeInterval=1</span></span><br><span class="line"><span class="comment">#主要是增加这三行(开始配置为主机名，存在问题，后改为ip地址)</span></span><br><span class="line">server.<span class="number">1</span>=<span class="number">192.168</span>.<span class="number">241.129</span>:<span class="number">2888</span>:<span class="number">3888</span></span><br><span class="line">server.<span class="number">2</span>=<span class="number">192.168</span>.<span class="number">241.130</span>:<span class="number">2888</span>:<span class="number">3888</span></span><br><span class="line">server.<span class="number">3</span>=<span class="number">192.168</span>.<span class="number">241.131</span>:<span class="number">2888</span>:<span class="number">3888</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#规则为：server.id=host:port1:port2</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#id是zookeeper集群各服务器的的id，host是各服务器ip或者主机名，</span></span><br><span class="line"><span class="comment">#port1是各服务器交互信息的端口，port2是当集群中的leader挂掉后重新选举的端口</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#各个服务器id是由myid文件指定，myid需要自己创建，文件只含一个数字，即id，范围为1-255</span></span><br><span class="line"><span class="comment">#myid文件路径为zoo.cfg里的dataDir目录</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#配置完毕，通过bin/zkServer.sh start启动服务，三个机器上都需要执行</span></span><br><span class="line"><span class="comment">#检查配置是否成功</span></span><br><span class="line">/usr/<span class="built_in">local</span>/zookeeper-<span class="number">3.4</span>.<span class="number">6</span>/zookeeper.out文件中查看时候一直存在异常信息输出</span><br></pre></td></tr></table></figure>
<h2 id="u6570_u636E_u64CD_u4F5C"><a href="#u6570_u636E_u64CD_u4F5C" class="headerlink" title="数据操作"></a>数据操作</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#客户端连接zookeeper服务，此时进入客户端交互界面</span></span><br><span class="line"><span class="variable">$bin</span>/zkCli.sh -server localhost:<span class="number">2181</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#查看节点（列出指定node的子node）：ls</span></span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">5</span>] ls /</span><br><span class="line">[zookeeper]</span><br><span class="line"></span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">5</span>] ls /hello</span><br><span class="line">[]</span><br><span class="line"></span><br><span class="line"><span class="comment">#创建一个测试节点hello 关联数据world</span></span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">6</span>] create /hello world</span><br><span class="line">Created /hello</span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">7</span>] ls /</span><br><span class="line">[hello, zookeeper]</span><br><span class="line"></span><br><span class="line"><span class="comment">#查看节点hello</span></span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">8</span>] get /hello</span><br><span class="line">world</span><br><span class="line">cZxid = <span class="number">0</span>x8</span><br><span class="line">ctime = Fri Apr <span class="number">10</span> <span class="number">13</span>:<span class="number">27</span>:<span class="number">35</span> CST <span class="number">2015</span></span><br><span class="line">mZxid = <span class="number">0</span>x8</span><br><span class="line">mtime = Fri Apr <span class="number">10</span> <span class="number">13</span>:<span class="number">27</span>:<span class="number">35</span> CST <span class="number">2015</span></span><br><span class="line">pZxid = <span class="number">0</span>x8</span><br><span class="line">cversion = <span class="number">0</span></span><br><span class="line">dataVersion = <span class="number">0</span></span><br><span class="line">aclVersion = <span class="number">0</span></span><br><span class="line">ephemeralOwner = <span class="number">0</span>x0</span><br><span class="line">dataLength = <span class="number">5</span></span><br><span class="line">numChildren = <span class="number">0</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#修改hello节点关联的数据</span></span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">9</span>] <span class="built_in">set</span> /hello new_world</span><br><span class="line">cZxid = <span class="number">0</span>x8</span><br><span class="line">ctime = Fri Apr <span class="number">10</span> <span class="number">13</span>:<span class="number">27</span>:<span class="number">35</span> CST <span class="number">2015</span></span><br><span class="line">mZxid = <span class="number">0</span>x9</span><br><span class="line">mtime = Fri Apr <span class="number">10</span> <span class="number">13</span>:<span class="number">30</span>:<span class="number">22</span> CST <span class="number">2015</span></span><br><span class="line">pZxid = <span class="number">0</span>x8</span><br><span class="line">cversion = <span class="number">0</span></span><br><span class="line">dataVersion = <span class="number">1</span> <span class="comment">#与第6步相比增加了1</span></span><br><span class="line">aclVersion = <span class="number">0</span></span><br><span class="line">ephemeralOwner = <span class="number">0</span>x0</span><br><span class="line">dataLength = <span class="number">9</span> <span class="comment">#new_world的字节数</span></span><br><span class="line">numChildren = <span class="number">0</span></span><br><span class="line"></span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">10</span>] get /hello</span><br><span class="line">new_world</span><br><span class="line">cZxid = <span class="number">0</span>x8</span><br><span class="line">ctime = Fri Apr <span class="number">10</span> <span class="number">13</span>:<span class="number">27</span>:<span class="number">35</span> CST <span class="number">2015</span></span><br><span class="line">mZxid = <span class="number">0</span>x9</span><br><span class="line">mtime = Fri Apr <span class="number">10</span> <span class="number">13</span>:<span class="number">30</span>:<span class="number">22</span> CST <span class="number">2015</span></span><br><span class="line">pZxid = <span class="number">0</span>x8</span><br><span class="line">cversion = <span class="number">0</span></span><br><span class="line">dataVersion = <span class="number">1</span></span><br><span class="line">aclVersion = <span class="number">0</span></span><br><span class="line">ephemeralOwner = <span class="number">0</span>x0</span><br><span class="line">dataLength = <span class="number">9</span></span><br><span class="line">numChildren = <span class="number">0</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#删除节点</span></span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">11</span>] delete /hello</span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">12</span>] ls /</span><br><span class="line">[zookeeper]</span><br><span class="line"><span class="comment">#使用delete命令可以删除指定znode。当该znode拥有子znode时, 必须先删除其所有子znode, 否则操作将失败。</span></span><br><span class="line"><span class="comment">#rmr命令可用于代替delete命令, rmr是一个递归删除命令, 如果发生指定节点拥有子节点时, rmr命令会首先删除子节点.</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#创建子节点</span></span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">17</span>] ls /</span><br><span class="line">[zookeeper]</span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">18</span>] create /hello world  <span class="comment">#创建节点时必须带上关联的数据</span></span><br><span class="line">Created /hello</span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">19</span>] create /hello/child child_world <span class="comment">#必须先创建节点hello，再创建child</span></span><br><span class="line">Created /hello/child</span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">20</span>] ls /</span><br><span class="line">[hello, zookeeper]</span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">21</span>] ls /hello</span><br><span class="line">[child]</span><br></pre></td></tr></table></figure>
<h2 id="u8282_u70B9_u5143_u6570_u636E"><a href="#u8282_u70B9_u5143_u6570_u636E" class="headerlink" title="节点元数据"></a>节点元数据</h2><p>　　在zookeeper中每个节点称为一个znode. 每个znode由3部分组成<br>　　1. stat：此为状态信息，描述该znode的版本，权限等信息<br>　　2. data：与该znode关联的数据<br>　　3. children：该znode下的子节点<br>　　在上面的操作中，使用了get命令获取指定节点的数据时，同时也返回了该节点的状态信息，称为Stat，其包含如下字段:<br>　　1. czxid：节点创建时的zxid<br>　　2. ctime：节点创建时的时间戳<br>　　3. mzxid：节点最新一次更新发生时的zxid<br>　　4. mtime：节点最新一次更新发生时的时间戳<br>　　5. dataVersion：节点数据的更新次数<br>　　6. cversion：其子节点的更新次数<br>　　7. aclVersion：节点ACL(授权信息)的更新次数<br>　　8. ephemeralOwner：如果该节点为ephemeral节点，ephemeralOwner值表示与该节点绑定的session id。如果该节点不是ephemeral节点，ephemeralOwner值为0。至于什么是ephemeral节点，请看后面的讲述<br>　　9. dataLength：节点数据的字节数<br>　　10. numChildren：子节点个数</p>
<h4 id="zxid"><a href="#zxid" class="headerlink" title="zxid"></a>zxid</h4><p>　　ZooKeeper状态的每一次改变，都对应着一个递增的Transaction id，该id称为zxid。由于zxid的递增性质，如果zxid1小于zxid2，那么zxid1肯定先于zxid2发生。创建任意节点，或者更新任意节点的数据，或者删除任意节点，都会导致Zookeeper状态发生改变，从而导致zxid的值增加。</p>
<h4 id="session"><a href="#session" class="headerlink" title="session"></a>session</h4><p>　　在client和server通信之前，首先需要建立连接，该连接称为session。连接建立后，如果发生连接超时，授权失败，或者显式关闭连接，连接便处于CLOSED状态，此时session结束。</p>
<h2 id="u8282_u70B9_u7C7B_u578B"><a href="#u8282_u70B9_u7C7B_u578B" class="headerlink" title="节点类型"></a>节点类型</h2><p>　　讲述节点状态的ephemeralOwner字段时，提到过有的节点是ephemeral节点，而有的并不是。那么节点都具有哪些类型呢，每种类型的节点又具有哪些特点呢？<br>　　1. persistent：persistent节点不和特定的session绑定，不会随着创建该节点的session的结束而消失，而是一直存在，除非该节点被显式删除。<br>　　2. ephemeral：ephemeral节点是临时性的，如果创建该节点的session结束了，该节点就会被自动删除，ephemeral节点不能拥有子节点。虽然ephemeral节点与创建它的session绑定，但只要该节点没有被删除，其他session就可以读写该节点中关联的数据。使用-e参数指定创建ephemeral节点（create -e /xing/ei world），其应用场景主要包括：<br>　　<strong>分布式集群是否存活监控</strong>：每个节点启动后，注册一个EPHEMERAL节点到zookeeper中，注册一个Watcher获取EPHEMERAL节点的存在情况，消失即可代表集群节点dead)<br>　　<strong>分布式lock</strong>：每个锁竞争者，排队时都在zookeeper中注册一个EPHEMERAL节点，排队过程中有节点dead了，zookeeper可以自动将其剔除队列，避免出现deadlock<br>　　<strong>替代web服务器的session</strong>：实现一个集中式session，session数据中的setAttribute都创建为EPHEMERAL节点，session关闭后即可自动删除，不会造成java中的内存泄漏<br>　　3. sequence：严格的说，sequence并非节点类型中的一种。sequence节点既可以是ephemeral的，也可以是persistent的。创建sequence节点时，ZooKeeper Server会在指定的节点名称后加上一个数字序列，该数字序列是递增的。因此可以多次创建相同的sequence节点，而得到不同的节点。使用-s参数指定创建sequence节点。<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[zk: localhost:<span class="number">4180</span>(CONNECTED) <span class="number">2</span>] create <span class="operator">-s</span> /snode world</span><br><span class="line">Created /xing/item0000000003</span><br><span class="line">[zk: localhost:<span class="number">4180</span>(CONNECTED) <span class="number">3</span>] create <span class="operator">-s</span> /snode world</span><br><span class="line">Created /xing/item0000000004</span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">33</span>] ls /</span><br><span class="line">[hello, snode0000000003, zookeeper, snode0000000004]</span><br></pre></td></tr></table></figure></p>
<h2 id="u4E8B_u4EF6_u76D1_u542C"><a href="#u4E8B_u4EF6_u76D1_u542C" class="headerlink" title="事件监听"></a>事件监听</h2><p>　　watch的意思是监听感兴趣的事件，在命令行中，以下几个命令可以指定是否监听相应的事件：</p>
<h4 id="ls_u547D_u4EE4"><a href="#ls_u547D_u4EE4" class="headerlink" title="ls命令"></a>ls命令</h4><p>　　ls命令的第一个参数指定znode，第二个参数如果为true，则说明监听该znode的子节点的增减，以及该znode本身的删除事件（实测没有）<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">41</span>] create /<span class="built_in">test</span> tt</span><br><span class="line">Created /<span class="built_in">test</span></span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">42</span>] ls /<span class="built_in">test</span> <span class="literal">true</span></span><br><span class="line">[]</span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">43</span>] create /<span class="built_in">test</span>/child c  <span class="comment">#监听子节点的添加</span></span><br><span class="line">WATCHER::</span><br><span class="line">WatchedEvent state:SyncConnected <span class="built_in">type</span>:NodeChildrenChanged path:/<span class="built_in">test</span></span><br><span class="line">Created /<span class="built_in">test</span>/child</span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">44</span>] <span class="built_in">set</span> /<span class="built_in">test</span> new_tt  <span class="comment">#更新节点并未触发事件</span></span><br><span class="line">cZxid = <span class="number">0</span>x19</span><br><span class="line">ctime = Fri Apr <span class="number">10</span> <span class="number">14</span>:<span class="number">19</span>:<span class="number">28</span> CST <span class="number">2015</span></span><br><span class="line">mZxid = <span class="number">0</span>x1b</span><br><span class="line">mtime = Fri Apr <span class="number">10</span> <span class="number">14</span>:<span class="number">20</span>:<span class="number">07</span> CST <span class="number">2015</span></span><br><span class="line">pZxid = <span class="number">0</span>x1a</span><br><span class="line">cversion = <span class="number">1</span></span><br><span class="line">dataVersion = <span class="number">1</span></span><br><span class="line">aclVersion = <span class="number">0</span></span><br><span class="line">ephemeralOwner = <span class="number">0</span>x0</span><br><span class="line">dataLength = <span class="number">6</span></span><br><span class="line">numChildren = <span class="number">1</span></span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">45</span>] delete /<span class="built_in">test</span>/child <span class="comment">#删除节点也未触发事件</span></span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">46</span>] delete /<span class="built_in">test</span></span><br></pre></td></tr></table></figure></p>
<h4 id="get_u547D_u4EE4"><a href="#get_u547D_u4EE4" class="headerlink" title="get命令"></a>get命令</h4><p>　　get命令的第一个参数指定znode，第二个参数如果为true，则说明监听该znode的更新和删除事件<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">35</span>] get /hello <span class="literal">true</span></span><br><span class="line">world</span><br><span class="line">cZxid = <span class="number">0</span>xb</span><br><span class="line">ctime = Fri Apr <span class="number">10</span> <span class="number">14</span>:<span class="number">00</span>:<span class="number">17</span> CST <span class="number">2015</span></span><br><span class="line">mZxid = <span class="number">0</span>xb</span><br><span class="line">mtime = Fri Apr <span class="number">10</span> <span class="number">14</span>:<span class="number">00</span>:<span class="number">17</span> CST <span class="number">2015</span></span><br><span class="line">pZxid = <span class="number">0</span>xc</span><br><span class="line">cversion = <span class="number">1</span></span><br><span class="line">dataVersion = <span class="number">0</span></span><br><span class="line">aclVersion = <span class="number">0</span></span><br><span class="line">ephemeralOwner = <span class="number">0</span>x0</span><br><span class="line">dataLength = <span class="number">5</span></span><br><span class="line">numChildren = <span class="number">1</span></span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">36</span>] create /hello/c cc  <span class="comment">#创建子节点，并未触发监听事件</span></span><br><span class="line">Created /hello/c</span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">40</span>] <span class="built_in">set</span> /hello new_t    <span class="comment">#修改节点数据，触发监听事件</span></span><br><span class="line">WATCHER::</span><br><span class="line">WatchedEvent state:SyncConnected <span class="built_in">type</span>:NodeDataChanged path:/hello</span><br><span class="line">cZxid = <span class="number">0</span>x17</span><br><span class="line">ctime = Fri Apr <span class="number">10</span> <span class="number">14</span>:<span class="number">14</span>:<span class="number">58</span> CST <span class="number">2015</span></span><br><span class="line">mZxid = <span class="number">0</span>x18</span><br><span class="line">mtime = Fri Apr <span class="number">10</span> <span class="number">14</span>:<span class="number">15</span>:<span class="number">30</span> CST <span class="number">2015</span></span><br><span class="line">pZxid = <span class="number">0</span>x17</span><br><span class="line">cversion = <span class="number">0</span></span><br><span class="line">dataVersion = <span class="number">1</span></span><br><span class="line">aclVersion = <span class="number">0</span></span><br><span class="line">ephemeralOwner = <span class="number">0</span>x0</span><br><span class="line">dataLength = <span class="number">5</span></span><br><span class="line">numChildren = <span class="number">0</span></span><br><span class="line"></span><br><span class="line">[zk: localhost:<span class="number">2181</span>(CONNECTED) <span class="number">37</span>] rmr /hello  <span class="comment">#删除节点，触发监听事件</span></span><br><span class="line">WATCHER::</span><br><span class="line">WatchedEvent state:SyncConnected <span class="built_in">type</span>:NodeDeleted path:/hello</span><br></pre></td></tr></table></figure></p>
<p>　　总结：<br>　　get：监听节点的删除和修改，添加子节点不会触发事件<br>　　ls：监听子节点的添加，删除和更新节点并不会触发事件<br>　　如需监听子节点，get和ls只需要指定子节点即可，如：get /node/child true<br>　　一次注册只能监听一次事件，每次监听后重新注册时间？</p>
<h4 id="stat_u547D_u4EE4"><a href="#stat_u547D_u4EE4" class="headerlink" title="stat命令"></a>stat命令</h4><p>　　stat命令用于获取znode的状态信息，第一个参数指定znode，如果第二个参数为true，则监听该node的更新和删除事件。</p>
<h2 id="u53C2_u8003_u94FE_u63A5"><a href="#u53C2_u8003_u94FE_u63A5" class="headerlink" title="参考链接"></a>参考链接</h2><p><a href="http://www.cnblogs.com/Xrinehart/p/3512509.html" target="_blank" rel="external">http://www.cnblogs.com/Xrinehart/p/3512509.html</a><br><a href="http://blog.csdn.net/lastsweetop/article/details/8794473" target="_blank" rel="external">http://blog.csdn.net/lastsweetop/article/details/8794473</a></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2016/01/09/zookeeper/1.zookeeper系列之入门/" data-id="cijzzpv0u000t1cfsmjtls9zk" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/zookeeper/">zookeeper</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2016/01/09/zookeeper/2.zookeeper系列之原理/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          zookeeper系列二之原理
        
      </div>
    </a>
  
  
    <a href="/2016/01/08/cache/3.Cache系列之一致性哈希算法/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Cache系列三之一致性哈希算法</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/cache/">cache</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/database/">database</a><span class="category-list-count">13</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/docker/">docker</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/gis/">gis</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/git/">git</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/go/">go</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/gradle/">gradle</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/groovy/">groovy</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/hadoop/">hadoop</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/java/">java</a><span class="category-list-count">18</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/linux/">linux</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/log/">log</a><span class="category-list-count">11</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mongodb/">mongodb</a><span class="category-list-count">14</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mq/">mq</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mybatis/">mybatis</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/netty/">netty</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nginx/">nginx</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nio/">nio</a><span class="category-list-count">19</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nodejs/">nodejs</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/redis/">redis</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/rpc/">rpc</a><span class="category-list-count">14</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/spring/">spring</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/tomcat/">tomcat</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/zookeeper/">zookeeper</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/杂项/">杂项</a><span class="category-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/aop/">aop</a><span class="tag-list-count">8</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/aspectj/">aspectj</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cache/">cache</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/classloader/">classloader</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/common-loggings/">common-loggings</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/commonjs/">commonjs</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/database/">database</a><span class="tag-list-count">10</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker/">docker</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/dubbo/">dubbo</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/fastdfs/">fastdfs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gclib/">gclib</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/geohash/">geohash</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gis/">gis</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/">git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/go/">go</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gradle/">gradle</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/groovy/">groovy</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hadoop/">hadoop</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hessisan/">hessisan</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/">java</a><span class="tag-list-count">48</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/javassist/">javassist</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/kafka/">kafka</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/log/">log</a><span class="tag-list-count">11</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/log4j/">log4j</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/logback/">logback</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/map/">map</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/memecached/">memecached</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mina/">mina</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mongodb/">mongodb</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mq/">mq</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mqtt/">mqtt</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mybatis/">mybatis</a><span class="tag-list-count">9</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/netty/">netty</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx/">nginx</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nio/">nio</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nodejs/">nodejs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/postgresql/">postgresql</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/protobuf/">protobuf</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/proxy/">proxy</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/push/">push</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/rabbitmq/">rabbitmq</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/redis/">redis</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/rpc/">rpc</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sitemesh/">sitemesh</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sld/">sld</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/slf4j/">slf4j</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/socket/">socket</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spatialite-for-android/">spatialite for android</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spi/">spi</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spring/">spring</a><span class="tag-list-count">13</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/tomcat/">tomcat</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/transaction/">transaction</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/web/">web</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/xSocket/">xSocket</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zbus/">zbus</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zookeeper/">zookeeper</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/数据结构/">数据结构</a><span class="tag-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/aop/" style="font-size: 15.38px;">aop</a> <a href="/tags/aspectj/" style="font-size: 11.54px;">aspectj</a> <a href="/tags/cache/" style="font-size: 11.54px;">cache</a> <a href="/tags/classloader/" style="font-size: 10px;">classloader</a> <a href="/tags/common-loggings/" style="font-size: 10px;">common-loggings</a> <a href="/tags/commonjs/" style="font-size: 12.31px;">commonjs</a> <a href="/tags/database/" style="font-size: 16.92px;">database</a> <a href="/tags/docker/" style="font-size: 13.85px;">docker</a> <a href="/tags/dubbo/" style="font-size: 10px;">dubbo</a> <a href="/tags/fastdfs/" style="font-size: 10px;">fastdfs</a> <a href="/tags/gclib/" style="font-size: 10.77px;">gclib</a> <a href="/tags/geohash/" style="font-size: 10px;">geohash</a> <a href="/tags/gis/" style="font-size: 10px;">gis</a> <a href="/tags/git/" style="font-size: 10.77px;">git</a> <a href="/tags/go/" style="font-size: 10px;">go</a> <a href="/tags/gradle/" style="font-size: 10px;">gradle</a> <a href="/tags/groovy/" style="font-size: 10px;">groovy</a> <a href="/tags/hadoop/" style="font-size: 10px;">hadoop</a> <a href="/tags/hessisan/" style="font-size: 11.54px;">hessisan</a> <a href="/tags/java/" style="font-size: 20px;">java</a> <a href="/tags/javassist/" style="font-size: 10px;">javassist</a> <a href="/tags/kafka/" style="font-size: 11.54px;">kafka</a> <a href="/tags/linux/" style="font-size: 12.31px;">linux</a> <a href="/tags/log/" style="font-size: 17.69px;">log</a> <a href="/tags/log4j/" style="font-size: 12.31px;">log4j</a> <a href="/tags/logback/" style="font-size: 13.08px;">logback</a> <a href="/tags/map/" style="font-size: 10px;">map</a> <a href="/tags/memecached/" style="font-size: 10.77px;">memecached</a> <a href="/tags/mina/" style="font-size: 13.08px;">mina</a> <a href="/tags/mongodb/" style="font-size: 19.23px;">mongodb</a> <a href="/tags/mq/" style="font-size: 13.85px;">mq</a> <a href="/tags/mqtt/" style="font-size: 10.77px;">mqtt</a> <a href="/tags/mybatis/" style="font-size: 16.15px;">mybatis</a> <a href="/tags/netty/" style="font-size: 10px;">netty</a> <a href="/tags/nginx/" style="font-size: 11.54px;">nginx</a> <a href="/tags/nio/" style="font-size: 13.08px;">nio</a> <a href="/tags/nodejs/" style="font-size: 10px;">nodejs</a> <a href="/tags/postgresql/" style="font-size: 10.77px;">postgresql</a> <a href="/tags/protobuf/" style="font-size: 10px;">protobuf</a> <a href="/tags/proxy/" style="font-size: 10px;">proxy</a> <a href="/tags/push/" style="font-size: 10px;">push</a> <a href="/tags/rabbitmq/" style="font-size: 11.54px;">rabbitmq</a> <a href="/tags/redis/" style="font-size: 13.85px;">redis</a> <a href="/tags/rpc/" style="font-size: 19.23px;">rpc</a> <a href="/tags/sitemesh/" style="font-size: 10px;">sitemesh</a> <a href="/tags/sld/" style="font-size: 10px;">sld</a> <a href="/tags/slf4j/" style="font-size: 10px;">slf4j</a> <a href="/tags/socket/" style="font-size: 14.62px;">socket</a> <a href="/tags/spatialite-for-android/" style="font-size: 10px;">spatialite for android</a> <a href="/tags/spi/" style="font-size: 10px;">spi</a> <a href="/tags/spring/" style="font-size: 18.46px;">spring</a> <a href="/tags/tomcat/" style="font-size: 10.77px;">tomcat</a> <a href="/tags/transaction/" style="font-size: 10px;">transaction</a> <a href="/tags/web/" style="font-size: 10px;">web</a> <a href="/tags/xSocket/" style="font-size: 14.62px;">xSocket</a> <a href="/tags/zbus/" style="font-size: 10px;">zbus</a> <a href="/tags/zookeeper/" style="font-size: 10.77px;">zookeeper</a> <a href="/tags/数据结构/" style="font-size: 10.77px;">数据结构</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/01/">January 2016</a><span class="archive-list-count">67</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/12/">December 2015</a><span class="archive-list-count">81</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/11/">November 2015</a><span class="archive-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recents</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2016/01/30/资料/">(no title)</a>
          </li>
        
          <li>
            <a href="/2016/01/30/java/13.Classloader系列一/">ClassLoader系列一</a>
          </li>
        
          <li>
            <a href="/2016/01/29/hadoop/1.hadoop系列之源码编译/">hadoop系列一之源码编译</a>
          </li>
        
          <li>
            <a href="/2016/01/29/go/1.GO系列之入门/">Go系列一之入门</a>
          </li>
        
          <li>
            <a href="/2016/01/28/tomcat/2.tomcat性能优化/">tomcat性能优化</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2016 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="http://libs.baidu.com/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">
  <script src="/fancybox/jquery.fancybox.pack.js" type="text/javascript"></script>


<script src="/js/script.js" type="text/javascript"></script>

  </div>
</body>
</html>